#include <deque>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; i++)
        cin >> nums[i];
    deque<int> d;
    vector<int> res(n);
    for (int i = 0; i < n; i++)
    {
        int x = nums[i];
        if (d.size() && d.front() <= x)
            d.push_front(x);
        else if (d.size() && d.front() > x)
        {
            while (d.size() && d.back() < x)
                d.pop_back();
            d.push_back(x);
        }
        else    d.push_back(x);
        int t = d.front();
        d.pop_front();
        res[i] = d.front();
        d.push_front(t);
    }

    int q, l;
    cin >> q;
    while (q--)
    {
        cin >> l;
        cout << res[l - 1] << endl;
    }
    return 0;
}